﻿using System;
using Microsoft.Xna.Framework;

namespace Terraria.World.Generation
{
	// Token: 0x02000097 RID: 151
	public static class Modifiers
	{
		// Token: 0x02000098 RID: 152
		public class ShapeScale : GenAction
		{
			// Token: 0x06000A44 RID: 2628 RVA: 0x0000B0BB File Offset: 0x000092BB
			public ShapeScale(int scale)
			{
				this._scale = scale;
			}

			// Token: 0x06000A45 RID: 2629 RVA: 0x003E5A08 File Offset: 0x003E3C08
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				bool flag = false;
				for (int i = 0; i < this._scale; i++)
				{
					for (int j = 0; j < this._scale; j++)
					{
						flag |= !base.UnitApply(origin, (x - origin.X << 1) + i + origin.X, (y - origin.Y << 1) + j + origin.Y, new object[0]);
					}
				}
				return !flag;
			}

			// Token: 0x04000EBC RID: 3772
			private int _scale;
		}

		// Token: 0x02000099 RID: 153
		public class Expand : GenAction
		{
			// Token: 0x06000A46 RID: 2630 RVA: 0x0000B0CA File Offset: 0x000092CA
			public Expand(int expansion)
			{
				this._xExpansion = expansion;
				this._yExpansion = expansion;
			}

			// Token: 0x06000A47 RID: 2631 RVA: 0x0000B0E0 File Offset: 0x000092E0
			public Expand(int xExpansion, int yExpansion)
			{
				this._xExpansion = xExpansion;
				this._yExpansion = yExpansion;
			}

			// Token: 0x06000A48 RID: 2632 RVA: 0x003E5A78 File Offset: 0x003E3C78
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				bool flag = false;
				for (int i = -this._xExpansion; i <= this._xExpansion; i++)
				{
					for (int j = -this._yExpansion; j <= this._yExpansion; j++)
					{
						flag |= !base.UnitApply(origin, x + i, y + j, args);
					}
				}
				return !flag;
			}

			// Token: 0x04000EBD RID: 3773
			private int _xExpansion;

			// Token: 0x04000EBE RID: 3774
			private int _yExpansion;
		}

		// Token: 0x0200009A RID: 154
		public class RadialDither : GenAction
		{
			// Token: 0x06000A49 RID: 2633 RVA: 0x0000B0F6 File Offset: 0x000092F6
			public RadialDither(float innerRadius, float outerRadius)
			{
				this._innerRadius = innerRadius;
				this._outerRadius = outerRadius;
			}

			// Token: 0x06000A4A RID: 2634 RVA: 0x003E5AD0 File Offset: 0x003E3CD0
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				Vector2 value = new Vector2((float)origin.X, (float)origin.Y);
				Vector2 value2 = new Vector2((float)x, (float)y);
				float num = Vector2.Distance(value2, value);
				float num2 = Math.Max(0f, Math.Min(1f, (num - this._innerRadius) / (this._outerRadius - this._innerRadius)));
				if (GenBase._random.NextDouble() > (double)num2)
				{
					return base.UnitApply(origin, x, y, args);
				}
				return base.Fail();
			}

			// Token: 0x04000EBF RID: 3775
			private float _innerRadius;

			// Token: 0x04000EC0 RID: 3776
			private float _outerRadius;
		}

		// Token: 0x0200009B RID: 155
		public class Blotches : GenAction
		{
			// Token: 0x06000A4B RID: 2635 RVA: 0x0000B10C File Offset: 0x0000930C
			public Blotches(int scale = 2, double chance = 0.3)
			{
				this._minX = scale;
				this._minY = scale;
				this._maxX = scale;
				this._maxY = scale;
				this._chance = chance;
			}

			// Token: 0x06000A4C RID: 2636 RVA: 0x0000B137 File Offset: 0x00009337
			public Blotches(int xScale, int yScale, double chance = 0.3)
			{
				this._minX = xScale;
				this._maxX = xScale;
				this._minY = yScale;
				this._maxY = yScale;
				this._chance = chance;
			}

			// Token: 0x06000A4D RID: 2637 RVA: 0x0000B162 File Offset: 0x00009362
			public Blotches(int leftScale, int upScale, int rightScale, int downScale, double chance = 0.3)
			{
				this._minX = leftScale;
				this._maxX = rightScale;
				this._minY = upScale;
				this._maxY = downScale;
				this._chance = chance;
			}

			// Token: 0x06000A4E RID: 2638 RVA: 0x003E5B50 File Offset: 0x003E3D50
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				GenBase._random.NextDouble();
				if (GenBase._random.NextDouble() < this._chance)
				{
					bool flag = false;
					int num = GenBase._random.Next(1 - this._minX, 1);
					int num2 = GenBase._random.Next(0, this._maxX);
					int num3 = GenBase._random.Next(1 - this._minY, 1);
					int num4 = GenBase._random.Next(0, this._maxY);
					for (int i = num; i <= num2; i++)
					{
						for (int j = num3; j <= num4; j++)
						{
							flag |= !base.UnitApply(origin, x + i, y + j, args);
						}
					}
					return !flag;
				}
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000EC1 RID: 3777
			private int _minX;

			// Token: 0x04000EC2 RID: 3778
			private int _minY;

			// Token: 0x04000EC3 RID: 3779
			private int _maxX;

			// Token: 0x04000EC4 RID: 3780
			private int _maxY;

			// Token: 0x04000EC5 RID: 3781
			private double _chance;
		}

		// Token: 0x0200009C RID: 156
		public class Conditions : GenAction
		{
			// Token: 0x06000A4F RID: 2639 RVA: 0x0000B18F File Offset: 0x0000938F
			public Conditions(params GenCondition[] conditions)
			{
				this._conditions = conditions;
			}

			// Token: 0x06000A50 RID: 2640 RVA: 0x003E5C14 File Offset: 0x003E3E14
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				bool flag = true;
				for (int i = 0; i < this._conditions.Length; i++)
				{
					flag &= this._conditions[i].IsValid(x, y);
				}
				if (flag)
				{
					return base.UnitApply(origin, x, y, args);
				}
				return base.Fail();
			}

			// Token: 0x04000EC6 RID: 3782
			private GenCondition[] _conditions;
		}

		// Token: 0x0200009D RID: 157
		public class OnlyWalls : GenAction
		{
			// Token: 0x06000A51 RID: 2641 RVA: 0x0000B19E File Offset: 0x0000939E
			public OnlyWalls(params byte[] types)
			{
				this._types = types;
			}

			// Token: 0x06000A52 RID: 2642 RVA: 0x003E5C60 File Offset: 0x003E3E60
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				for (int i = 0; i < this._types.Length; i++)
				{
					if (GenBase._tiles[x, y].wall == (ushort)this._types[i])
					{
						return base.UnitApply(origin, x, y, args);
					}
				}
				return base.Fail();
			}

			// Token: 0x04000EC7 RID: 3783
			private byte[] _types;
		}

		// Token: 0x0200009E RID: 158
		public class OnlyTiles : GenAction
		{
			// Token: 0x06000A53 RID: 2643 RVA: 0x0000B1AD File Offset: 0x000093AD
			public OnlyTiles(params ushort[] types)
			{
				this._types = types;
			}

			// Token: 0x06000A54 RID: 2644 RVA: 0x003E5CB0 File Offset: 0x003E3EB0
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				if (!GenBase._tiles[x, y].active())
				{
					return base.Fail();
				}
				for (int i = 0; i < this._types.Length; i++)
				{
					if (GenBase._tiles[x, y].type == this._types[i])
					{
						return base.UnitApply(origin, x, y, args);
					}
				}
				return base.Fail();
			}

			// Token: 0x04000EC8 RID: 3784
			private ushort[] _types;
		}

		// Token: 0x0200009F RID: 159
		public class IsTouching : GenAction
		{
			// Token: 0x06000A55 RID: 2645 RVA: 0x0000B1BC File Offset: 0x000093BC
			public IsTouching(bool useDiagonals, params ushort[] tileIds)
			{
				this._useDiagonals = useDiagonals;
				this._tileIds = tileIds;
			}

			// Token: 0x06000A56 RID: 2646 RVA: 0x003E5D18 File Offset: 0x003E3F18
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				int num = this._useDiagonals ? 16 : 8;
				for (int i = 0; i < num; i += 2)
				{
					Tile tile = GenBase._tiles[x + Modifiers.IsTouching.DIRECTIONS[i], y + Modifiers.IsTouching.DIRECTIONS[i + 1]];
					if (tile.active())
					{
						for (int j = 0; j < this._tileIds.Length; j++)
						{
							if (tile.type == this._tileIds[j])
							{
								return base.UnitApply(origin, x, y, args);
							}
						}
					}
				}
				return base.Fail();
			}

			// Token: 0x04000EC9 RID: 3785
			private static readonly int[] DIRECTIONS = new int[]
			{
				0,
				-1,
				1,
				0,
				-1,
				0,
				0,
				1,
				-1,
				-1,
				1,
				-1,
				-1,
				1,
				1,
				1
			};

			// Token: 0x04000ECA RID: 3786
			private bool _useDiagonals;

			// Token: 0x04000ECB RID: 3787
			private ushort[] _tileIds;
		}

		// Token: 0x020000A0 RID: 160
		public class NotTouching : GenAction
		{
			// Token: 0x06000A58 RID: 2648 RVA: 0x0000B1EB File Offset: 0x000093EB
			public NotTouching(bool useDiagonals, params ushort[] tileIds)
			{
				this._useDiagonals = useDiagonals;
				this._tileIds = tileIds;
			}

			// Token: 0x06000A59 RID: 2649 RVA: 0x003E5D9C File Offset: 0x003E3F9C
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				int num = this._useDiagonals ? 16 : 8;
				for (int i = 0; i < num; i += 2)
				{
					Tile tile = GenBase._tiles[x + Modifiers.NotTouching.DIRECTIONS[i], y + Modifiers.NotTouching.DIRECTIONS[i + 1]];
					if (tile.active())
					{
						for (int j = 0; j < this._tileIds.Length; j++)
						{
							if (tile.type == this._tileIds[j])
							{
								return base.Fail();
							}
						}
					}
				}
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000ECC RID: 3788
			private static readonly int[] DIRECTIONS = new int[]
			{
				0,
				-1,
				1,
				0,
				-1,
				0,
				0,
				1,
				-1,
				-1,
				1,
				-1,
				-1,
				1,
				1,
				1
			};

			// Token: 0x04000ECD RID: 3789
			private bool _useDiagonals;

			// Token: 0x04000ECE RID: 3790
			private ushort[] _tileIds;
		}

		// Token: 0x020000A1 RID: 161
		public class IsTouchingAir : GenAction
		{
			// Token: 0x06000A5B RID: 2651 RVA: 0x0000B21A File Offset: 0x0000941A
			public IsTouchingAir(bool useDiagonals = false)
			{
				this._useDiagonals = useDiagonals;
			}

			// Token: 0x06000A5C RID: 2652 RVA: 0x003E5E20 File Offset: 0x003E4020
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				int num = this._useDiagonals ? 16 : 8;
				for (int i = 0; i < num; i += 2)
				{
					if (!GenBase._tiles[x + Modifiers.IsTouchingAir.DIRECTIONS[i], y + Modifiers.IsTouchingAir.DIRECTIONS[i + 1]].active())
					{
						return base.UnitApply(origin, x, y, args);
					}
				}
				return base.Fail();
			}

			// Token: 0x04000ECF RID: 3791
			private static readonly int[] DIRECTIONS = new int[]
			{
				0,
				-1,
				1,
				0,
				-1,
				0,
				0,
				1,
				-1,
				-1,
				1,
				-1,
				-1,
				1,
				1,
				1
			};

			// Token: 0x04000ED0 RID: 3792
			private bool _useDiagonals;
		}

		// Token: 0x020000A2 RID: 162
		public class SkipTiles : GenAction
		{
			// Token: 0x06000A5E RID: 2654 RVA: 0x0000B242 File Offset: 0x00009442
			public SkipTiles(params ushort[] types)
			{
				this._types = types;
			}

			// Token: 0x06000A5F RID: 2655 RVA: 0x003E5E80 File Offset: 0x003E4080
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				if (!GenBase._tiles[x, y].active())
				{
					return base.UnitApply(origin, x, y, args);
				}
				for (int i = 0; i < this._types.Length; i++)
				{
					if (GenBase._tiles[x, y].type == this._types[i])
					{
						return base.Fail();
					}
				}
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000ED1 RID: 3793
			private ushort[] _types;
		}

		// Token: 0x020000A3 RID: 163
		public class HasLiquid : GenAction
		{
			// Token: 0x06000A60 RID: 2656 RVA: 0x0000B251 File Offset: 0x00009451
			public HasLiquid(int liquidLevel = -1, int liquidType = -1)
			{
				this._liquidLevel = liquidLevel;
				this._liquidType = liquidType;
			}

			// Token: 0x06000A61 RID: 2657 RVA: 0x003E5EEC File Offset: 0x003E40EC
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				Tile tile = GenBase._tiles[x, y];
				if ((this._liquidType == -1 || this._liquidType == (int)tile.liquidType()) && ((this._liquidLevel == -1 && tile.liquid != 0) || this._liquidLevel == (int)tile.liquid))
				{
					return base.UnitApply(origin, x, y, args);
				}
				return base.Fail();
			}

			// Token: 0x04000ED2 RID: 3794
			private int _liquidType;

			// Token: 0x04000ED3 RID: 3795
			private int _liquidLevel;
		}

		// Token: 0x020000A4 RID: 164
		public class SkipWalls : GenAction
		{
			// Token: 0x06000A62 RID: 2658 RVA: 0x0000B267 File Offset: 0x00009467
			public SkipWalls(params byte[] types)
			{
				this._types = types;
			}

			// Token: 0x06000A63 RID: 2659 RVA: 0x003E5F50 File Offset: 0x003E4150
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				for (int i = 0; i < this._types.Length; i++)
				{
					if (GenBase._tiles[x, y].wall == (ushort)this._types[i])
					{
						return base.Fail();
					}
				}
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000ED4 RID: 3796
			private byte[] _types;
		}

		// Token: 0x020000A5 RID: 165
		public class IsEmpty : GenAction
		{
			// Token: 0x06000A64 RID: 2660 RVA: 0x0000B276 File Offset: 0x00009476
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				if (!GenBase._tiles[x, y].active())
				{
					return base.UnitApply(origin, x, y, args);
				}
				return base.Fail();
			}
		}

		// Token: 0x020000A6 RID: 166
		public class IsSolid : GenAction
		{
			// Token: 0x06000A66 RID: 2662 RVA: 0x0000B29D File Offset: 0x0000949D
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				if (GenBase._tiles[x, y].active() && WorldGen.SolidTile(x, y))
				{
					return base.UnitApply(origin, x, y, args);
				}
				return base.Fail();
			}
		}

		// Token: 0x020000A7 RID: 167
		public class IsNotSolid : GenAction
		{
			// Token: 0x06000A68 RID: 2664 RVA: 0x0000B2CD File Offset: 0x000094CD
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				if (!GenBase._tiles[x, y].active() || !WorldGen.SolidTile(x, y))
				{
					return base.UnitApply(origin, x, y, args);
				}
				return base.Fail();
			}
		}

		// Token: 0x020000A8 RID: 168
		public class RectangleMask : GenAction
		{
			// Token: 0x06000A6A RID: 2666 RVA: 0x0000B2FD File Offset: 0x000094FD
			public RectangleMask(int xMin, int xMax, int yMin, int yMax)
			{
				this._xMin = xMin;
				this._yMin = yMin;
				this._xMax = xMax;
				this._yMax = yMax;
			}

			// Token: 0x06000A6B RID: 2667 RVA: 0x003E5FA0 File Offset: 0x003E41A0
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				if (x >= this._xMin + origin.X && x <= this._xMax + origin.X && y >= this._yMin + origin.Y && y <= this._yMax + origin.Y)
				{
					return base.UnitApply(origin, x, y, args);
				}
				return base.Fail();
			}

			// Token: 0x04000ED5 RID: 3797
			private int _xMin;

			// Token: 0x04000ED6 RID: 3798
			private int _yMin;

			// Token: 0x04000ED7 RID: 3799
			private int _xMax;

			// Token: 0x04000ED8 RID: 3800
			private int _yMax;
		}

		// Token: 0x020000A9 RID: 169
		public class Offset : GenAction
		{
			// Token: 0x06000A6C RID: 2668 RVA: 0x0000B322 File Offset: 0x00009522
			public Offset(int x, int y)
			{
				this._xOffset = x;
				this._yOffset = y;
			}

			// Token: 0x06000A6D RID: 2669 RVA: 0x0000B338 File Offset: 0x00009538
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				return base.UnitApply(origin, x + this._xOffset, y + this._yOffset, args);
			}

			// Token: 0x04000ED9 RID: 3801
			private int _xOffset;

			// Token: 0x04000EDA RID: 3802
			private int _yOffset;
		}

		// Token: 0x020000AA RID: 170
		public class Dither : GenAction
		{
			// Token: 0x06000A6E RID: 2670 RVA: 0x0000B353 File Offset: 0x00009553
			public Dither(double failureChance = 0.5)
			{
				this._failureChance = failureChance;
			}

			// Token: 0x06000A6F RID: 2671 RVA: 0x0000B362 File Offset: 0x00009562
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				if (GenBase._random.NextDouble() >= this._failureChance)
				{
					return base.UnitApply(origin, x, y, args);
				}
				return base.Fail();
			}

			// Token: 0x04000EDB RID: 3803
			private double _failureChance;
		}

		// Token: 0x020000AB RID: 171
		public class Flip : GenAction
		{
			// Token: 0x06000A70 RID: 2672 RVA: 0x0000B388 File Offset: 0x00009588
			public Flip(bool flipX, bool flipY)
			{
				this._flipX = flipX;
				this._flipY = flipY;
			}

			// Token: 0x06000A71 RID: 2673 RVA: 0x0000B39E File Offset: 0x0000959E
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				if (this._flipX)
				{
					x = origin.X * 2 - x;
				}
				if (this._flipY)
				{
					y = origin.Y * 2 - y;
				}
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000EDC RID: 3804
			private bool _flipX;

			// Token: 0x04000EDD RID: 3805
			private bool _flipY;
		}
	}
}
